var mysql      = require('mysql');
var connection = mysql.createConnection({
  host     : '127.0.0.1',
  user     : 'root',
  password : 'root',
  database : 'zuoye'
});
 
connection.connect(function(err) {
  if (err) {
    console.error('error connecting: ' + err.stack);
    return;
  }
 
  console.log('connected as id ' + connection.threadId);
});
// 增
connection.query(`INSERT into user VALUES('张三',14,'男','2023-02-21 16:40:08','2023-02-22 16:40:08'),('小芳',25,'女','2023-02-21 16:40:08','2023-02-23 16:40:08'),('小帅',20,'男','2023-02-21 16:40:08','2023-02-25 16:40:08');`,"测试",(error, results) =>{
    if (error) throw error;
    console.log(results);
});

// 删
connection.query(`DELETE FROM user WHERE NAME='张三';`,(error, results) =>{
    if (error) throw error;
    console.log(results);
});

// 查
connection.query('SELECT * from user', function (error, results, fields) {
    if (error) throw error;
    console.log("查询结果是");
    console.log(results);
});

// 改

connection.query(`UPDATE USER set update_time='2024-04-1 15:30:02' where name='小芳';`,(error, results) =>{
    if (error) throw error;
    console.log(results);
});

// 关闭连接
connection.end();
